/*
 * @Author: c
 * @Date: 2024-01-08 22:12:18
 * @LastEditTime: 2024-02-07 06:15:03
 * @LastEditors: c
 * @Description: 歌单实体类
 * @FilePath: \music-web-backend\src\core\music\track\entities\track.entity.ts
 * https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
 */
import { BasicEntity } from "src/common/entity/basic.entity";
import { FileInfo } from "src/core/system/minio/entities/file_info.entity";
import { User } from "src/core/system/user/entities/user.entity";
import { Column, Entity, JoinTable, ManyToMany, OneToOne, PrimaryGeneratedColumn } from "typeorm";
import { Category } from "../../category/entities/category.entity";
import { Song } from "../../song/entities/song.entity";

//歌单
@Entity({
    name: "track"
})
export class Track extends BasicEntity {

    //唯一ID
    @PrimaryGeneratedColumn()
    id: number;

    //歌单的标题
    @Column({
        name: "title",
        type: 'varchar',
        comment: "歌单的标题"
    })
    title: string;

    //歌单的描述
    @Column({
        name: "desc",
        type: 'varchar',
        comment: "歌单的描述"
    })
    desc: string;

    //类别标签
    @ManyToMany(() => Category, cate => cate.tracks, {
        cascade: true,
    })
    @JoinTable({
        name: "track_cate", //生成的中间表名
        joinColumn: {
            name: "track_id", //当前表名
            referencedColumnName: "id" //需要关联的列
        },
        inverseJoinColumn: {
            name: "cate_id", //需要被关联的表名
            referencedColumnName: "id"//需要关联的列
        }
    })
    tagList: Category[];

    //歌单中歌曲列表
    @ManyToMany(() => Song, song => song.trackList, {
        cascade: true,
    })
    @JoinTable({
        name: "track_song", //生成的中间表名
        joinColumn: {
            name: "track", //当前表名
            referencedColumnName: "id" //需要关联的列
        },
        inverseJoinColumn: {
            name: "song", //需要被关联的表名
            referencedColumnName: "id"//需要关联的列
        }
    })
    songList: Song[];

    //喜欢此歌单的人
    @ManyToMany(() => User, user => user.favorSongList, {
        cascade: true,
    })
    @JoinTable({
        name: "track_user_favor", //生成的中间表名
        joinColumn: {
            name: "track_id", //生成的列名
            referencedColumnName: "id" //需要关联的列
        },
        inverseJoinColumn: {
            name: "user_id", //需要被关联的生成的列名
            referencedColumnName: "id"//需要关联的列
        }
    })
    favoriteUsers: User[];

    //封面图
    @OneToOne(() => FileInfo, (file) => file.track, {
        cascade: ['remove'],
    })
    pic: FileInfo
}